package org.osgl.issues;

/*-
 * #%L
 * Java Tool
 * %%
 * Copyright (C) 2014 - 2018 OSGL (Open Source General Library)
 * %%
 * Licensed under the Apache License, Version 2.0 (the "License");
 * you may not use this file except in compliance with the License.
 * You may obtain a copy of the License at
 * 
 *      http://www.apache.org/licenses/LICENSE-2.0
 * 
 * Unless required by applicable law or agreed to in writing, software
 * distributed under the License is distributed on an "AS IS" BASIS,
 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
 * See the License for the specific language governing permissions and
 * limitations under the License.
 * #L%
 */

import org.junit.Test;
import org.osgl.$;
import org.osgl.TestBase;
import org.osgl.util.N;
import org.osgl.util.S;

public class Gh98 extends TestBase {

    public static class Bar {
        public String s1 = S.random();
        public String s2 = S.random();
        public String s3 = S.random();
    }

    public static class Foo {
        public Bar bar = new Bar();
        public int id = N.randInt();
    }

    @Test
    public void test() {
        Foo source = new Foo();
        Foo target = new Foo();

        $.deepCopy(source).filter("-bar,+bar.s2").to(target);
        Bar sourceBar = source.bar;
        Bar targetBar = target.bar;
        eq(source.id, target.id);
        ne(sourceBar.s1, targetBar.s1);
        eq(sourceBar.s2, targetBar.s2);
        ne(sourceBar.s1, targetBar.s1);
    }

    @Test
    public void testReverseCase() {
        Foo source = new Foo();
        Foo target = new Foo();

        $.deepCopy(source).filter("-bar.s2").to(target);
        Bar sourceBar = source.bar;
        Bar targetBar = target.bar;
        eq(source.id, target.id);
        eq(sourceBar.s1, targetBar.s1);
        ne(sourceBar.s2, targetBar.s2);
        eq(sourceBar.s1, targetBar.s1);
    }

}
